package joc.contract;

import joc.customize.Contract;
import joc.customize.PartialEvaluationResult;
import joc.customize.ForFieldEvaluateAtBeginningOfAllMethods;
import joc.customize.ForFieldEvaluateAtEndOfAllBehaviors;
import joc.customize.ForMethodEvaluateAtEndOfMethodWithReturnValueAndInherit;
import joc.customize.ForParameterEvaluateAtBeginningOfBehavior;

public class ContainsStringContract extends Contract<ContainsString> {
	@ForFieldEvaluateAtBeginningOfAllMethods
	@ForFieldEvaluateAtEndOfAllBehaviors
	@ForParameterEvaluateAtBeginningOfBehavior
	@ForMethodEvaluateAtEndOfMethodWithReturnValueAndInherit
	public PartialEvaluationResult checkContract(ContainsString annotation, String value) {
		for (String part : annotation.value()) {
			if (!value.contains(part)) {
				return getFailure("String '" + value + "' did not contain '" + part + "'.");
			}
		}
		return getSuccess();
	}

}
